package com.example.mytayunapi.Mapper;

import com.example.mytayunapi.Entity.conversationInfo;
import com.example.mytayunapi.Entity.messageInfo;
import com.example.mytayunapi.Vo.ConversionProductUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.logging.log4j.message.Message;

import javax.security.auth.message.MessageInfo;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.List;

@Mapper
public interface conversationInfoMapper {

    @Select("SELECT c.*, p.*, u.Nick_name\n" +
            "FROM conversation c\n" +
            "JOIN products p ON c.Product_id = p.Product_id\n" +
            "JOIN user u ON p.School_degree = u.School_degree\n" +
            "WHERE c.User_id = #{User_id}")
    List<ConversionProductUser> getAllConversion(String User_id);

    @Select("SELECT * FROM message WHERE Conversation_id = #{Conversation_id}")
    List<messageInfo> getMessageByConversation(Integer Conversation_id);

    @Insert("INSERT INTO message (Conversation_id, Send_id, Send_time, Send_content)\n" +
            "VALUES (#{Conversation_id}, #{Send_id}, NOW(), #{Send_content})")
    Integer insertMessage(messageInfo messageinfo);

    @Insert("insert into conversation(Product_id,User_id) values(#{Product_id},#{User_id})")
    Integer insertConversation(conversationInfo conversationInfo);

}
